/**
* @description: 520. 检测大写字母
* @author hewei
* @date 2022/8/10 16:32
* @version 1.0
*/

public class DetectCapitalUse {

    public static void main(String[] args) {
        DetectCapitalUse detectCapitalUse = new DetectCapitalUse();
        System.out.println(detectCapitalUse.detectCapitalUse("FlaG"));
    }

    public boolean detectCapitalUse(String word) {
        if (word.equals(toLower(word)) || word.equals(toUpper(word))) return true;
        return Character.isUpperCase(word.charAt(0)) && word.substring(1).equals(toLower(word.substring(1)));
    }

    public String toUpper(String s) {
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            chars[i] = Character.toUpperCase(chars[i]);
        }
        return new String(chars);
    }

    public String toLower(String s) {
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            chars[i] = Character.toLowerCase(chars[i]);
        }
        return new String(chars);
    }
}
